package cn.monkey.family.rbac.dsl.http;

public interface HttpRequestPredicate<REQUEST> {

    interface PredicateResult {
        int NO_MATCH = 0;
        int PATH_MATCH = 1;
        int METHOD_MATCH = 1 << 1;
        int HEADER_MATCH = 1 << 2;
        int PARAM_MATCH = 1 << 3;

        int MATCH = PATH_MATCH | METHOD_MATCH | HEADER_MATCH | PARAM_MATCH;
    }

    int match(REQUEST request);

    default HttpRequestPredicate<REQUEST> and(HttpRequestPredicate<REQUEST> predicate) {
        return request -> this.match(request) & predicate.match(request);
    }

    default HttpRequestPredicate<REQUEST> or(HttpRequestPredicate<REQUEST> predicate) {
        return request -> this.match(request) | predicate.match(request);
    }
}
